<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
        xmlns:icecore="http://www.icefaces.org/icefaces/core"
       xmlns:ace="http://www.icefaces.org/icefaces/components"
       xmlns:ice="http://www.icesoft.com/icefaces/component"
       >
    <h:head>
        <title><ice:outputText>Übungsgruppen bearbeiten</ice:outputText></title>
    </h:head>
    <h:body>
        <ui:composition template="WEB-INF/templates/lecture.xhtml">
            <ui:define name="content">
                <h:form>
                    <ice:outputText value="Übungsgruppe hinzufügen" /><br />
                    <ice:outputText value="Name" />
                    <ice:inputText value="#{exerciseGroupBean.newGroupName}" />
                    <ice:commandButton value="Hinzufügen"
                                       action="#{exerciseGroupBean.addGroup}" />
                </h:form>
                <br />
                <br />
                <ice:dataTable var="row"
                               value="#{exerciseGroupBean.exerciseGroupBeans}" >
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Name" /></f:facet>
                        <ice:inputText value="#{row.eg.name}" 
                                       partialSubmit="true"
                                       size="50"/>
                        <br />
                        <h:form>
                            <ice:commandButton value="Namen generieren"
                                               action="#{row.generateGroupName()}" />
                        </h:form>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Tutoren" /></f:facet>
                        <ice:dataTable var="tutor"
                                       value="#{row.eg.leaders}" >
                            <ice:column>
                                <f:facet name="header"><ice:outputText value="Name" /></f:facet>
                                <h:form><ice:outputText value="#{tutor}" />
                                <ice:commandLink value="X"
                                                 action="#{row.eg.removeLeader(tutor)}"
                                                 partialSubmit="true"/>
                                </h:form>
                            </ice:column>

                        </ice:dataTable>
                    </ice:column>
                    
                    <ice:column>
                        <h:form>
                            <ice:outputText value="Tutor hinzufügen" />
                            <ice:selectOneMenu value="#{row.tempLeader}"
                                               partialSubmit="true">
                                <f:selectItems value="#{lectureBean.lecture.tutors}"
                                               var="t"
                                               itemValue="#{t.username}"
                                               itemLabel="#{t.username}"/>
                            </ice:selectOneMenu>
                            <ice:commandButton value="Hinzufügen" 
                                               action="#{row.addLeader(row.tempLeader)}"/>
                            <ice:outputText value="User nicht vorhanden"
                                            rendered="#{!row.isLeaderValid}" />
                        </h:form>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Zeit zuordnen" /></f:facet>
                        <h:form>
                            <ice:selectOneMenu value="#{row.eg.time}"
                                               partialSubmit="true">
                                <f:converter converterId="weeklyDateConverter" />
                                <f:selectItems value="#{exerciseGroupBean.timeItems}"/>
                            </ice:selectOneMenu>
                            <ice:outputText value="#{row.eg.time.toString()}" />
                        </h:form>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Ort" /></f:facet>
                        <h:form>
                            <ice:inputText value="#{row.eg.place}" 
                                           partialSubmit="true"/>
                        </h:form>
                           
                    </ice:column>
                    
                    <ice:column>
                        
                        <h:form>
                            <ice:commandButton value="Löschen"
                                               action="#{exerciseGroupBean.removeGroup(row)}" />
                        </h:form>
                    </ice:column>
                </ice:dataTable>
                <br />
                <ice:outputText value="Zeiten für Übungsgruppentermine" />
                <br />
                <br />
                <ice:form>
                    <ice:commandButton value="Neue Zeit erstellen"
                                       action="#{lectureBean.lecture.createTime()}" />
                </ice:form>                    
                <br />
                <ice:form>
                <ice:dataTable value="#{lectureBean.lecture.times}"
                               var="time">
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Tag" /></f:facet>
                        <ice:selectOneMenu value="#{time.day}">
                            <f:selectItems value="#{exerciseGroupBean.dayItems}"/>
                        </ice:selectOneMenu>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Stunde"/></f:facet>
                        <ice:inputText value="#{time.hour}"
                                       partialSubmit="true">
                            <f:validateLongRange minimum="0"
                                                 maximum="24" />
                        </ice:inputText>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Minute" /></f:facet>
                        <ice:inputText value="#{time.minute}"
                                       partialSubmit="true">
                            <f:validateLongRange minimum="0"
                                                 maximum="60" />
                        </ice:inputText>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Dauer" /></f:facet>
                        <ice:inputText value="#{time.duration}"
                                       partialSubmit="true"/>
                    </ice:column>
                    <ice:column>
                            <ice:commandButton value="Löschen"
                                               action="#{lectureBean.lecture.removeTime(time)}" />
                    </ice:column>
                </ice:dataTable>
                </ice:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
